package ua.edu.sumdu.j2se.roman.lab1.view.swing;

import ua.edu.sumdu.j2se.roman.lab1.domain.Task;
import ua.edu.sumdu.j2se.roman.lab1.view.PostponeView;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Author: Radko Roman.
 */

/**
 * Describes interface of postpone view.
 *
 */
public class SwingPostponeView implements PostponeView {
    private JFrame viewForm;

    /**
     * Constructor that call the method of initializing all components on view form.
     *
     */
    public SwingPostponeView() {
        initView();
    }
    /**
     * Initialize all components on view form.
     *
     */
    private void initView() {
        viewForm = new JFrame("Postpone Task");
        viewForm.setSize(200, 200);
        viewForm.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        viewForm.setLocationRelativeTo(null);

        JButton postponeBtn = new JButton("Postpone");
        postponeBtn.setLocation(8, 30);
        postponeBtn.setSize(150, 35);
        postponeBtn.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(viewForm, "Task postponed!",
                        "Message", JOptionPane.INFORMATION_MESSAGE);
                viewForm.setVisible(false);
                viewForm.dispose();
            }

        });
        viewForm.getContentPane().add(postponeBtn);
    }
    /**
     * Show to user postpone swing view form with description of postponed task.
     *
     * @param t  postponed task
     */
    @Override
    public void show(Task t) {
        viewForm.setVisible(true);
    }
}
